import React from 'react';
import { withRouter, router } from 'umi';
import { message } from 'antd';
import { useRequest } from '@/hooks';
import { getHandoverContent } from '../service';
import { LEAVE_STATUS_OBJ, HANDOVER_PATH } from '../dictionary';
// 离职交接临时中转页
function HandoverTransfer(props) {
    const { location } = props;
    const { query, pathname } = location;
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { employeeCode, type = LEAVE_STATUS_OBJ.WorkHandover, dimissionOrderId } = query;
    const params = {
        dimissionOrderId,
        employeeCode,
        type,
        matterId: query?.matterId
    };
    const { run } = useRequest(() => getHandoverContent(params), {
        // const { data, loading } = useRequest(() => getHandoverDetailByOrderId(query?.dimissionOrderId), {
        ready: !!query?.dimissionOrderId,
        formatResult: res => {
            if (res) {
                const { code, data: data2, msg } = res;
                if (code === 10000) {
                    // 从待办和已完成待办都是跳转到这个页面，所以要判断跳转到交接页面还是交接详情页
                    if (data2.matterDetail[0].matterStatus === 3) {
                        history.replace({
                            pathname: '/office/personnelManagement/onboardAndLeave/leaveManagement/handover_detail',
                            query: {
                                dimissionOrderId: query?.dimissionOrderId,
                                employeeCode: query?.employeeCode
                            }
                        });
                    } else {
                        const path = HANDOVER_PATH[type];
                        if (path !== pathname && path) {
                            history.replace({
                                pathname: path,
                                query
                            });
                        }
                    }
                } else {
                    message.error(msg);
                }
            }
        }
    });
    React.useEffect(() => {
        // const path = HANDOVER_PATH[type];
        // if (path !== pathname && path) {
        //     history.replace({
        //         pathname: path,
        //         query
        //     });
        // }
        run();
    }, [pathname, type]);
    return <div></div>;
}
export default withRouter(HandoverTransfer);
